package tw.com.softleader.movie.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import tw.com.softleader.movie.dao.MovieDao;
import tw.com.softleader.movie.entity.Movie;

@Repository
public class MovieDaoImpl implements MovieDao{

	private static final Logger log = LoggerFactory.getLogger(MovieDaoImpl.class);
	
	private List<Movie> movies = new ArrayList<Movie>();
	
	@PostConstruct
	public void init(){
		log.debug("MovieDaoImpl - init()");

		Movie movie1 = new Movie();
		movie1.setId(1L);
		movie1.setName("Movie A");
		Movie movie2 = new Movie();
		movie2.setId(2L);
		movie2.setName("Movie B");
		movies.add(movie1);
		movies.add(movie2);
	}
	
	@Override
	public List<Movie> findAll() {
		log.debug("MovieDaoImpl - findAll()");
		return movies;
	}

	@Override
	public Movie findOne(Long id) {
		for(Movie movie : movies){
			if(movie.getId().equals(id)){
				return movie;
			}
		}
		return null;
	}

}
